using Kopernikus.Collections.Generic;
using Kopernikus.Parsing.Tests.TestUtility;
using NUnit.Framework;

namespace Kopernikus.Parsing.Tests
{
    [TestFixture]
    public class TestGrammarNullables : TestGrammarBase
    {
        private static IGrammar CreateGrammar()
        {
            string grammar =
                @"
PROGRAM
PROGRAM namespace id { DEFINITIONS }
DEFINITIONS
DEFINITIONS X DEFINITIONS
DEFINITIONS DEFINITION DEFINITIONS
DEFINITION class
X
";

            return ParseGrammar(grammar);
        }

        [Test]
        public void Test()
        {
            IGrammar grammar = CreateGrammar();
            Assert.AreEqual(MakeSymbolSet("PROGRAM", "DEFINITIONS", "X"), grammar.SymbolSets.NullableSymbols);

            Assert.AreEqual(
                new Set<Production>(
                    new Production[]
                        {
                            new Production("PROGRAM"),
                            new Production("DEFINITIONS"),
                            new Production("X"),
                            new Production("DEFINITIONS", "X", "DEFINITIONS")
                        }),
                grammar.ProductionSets.NullableProductions);
        }
    }
}